package com.htd.htdapmservice.facadeimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.htd.htdapmapi.alarm.facade.intf.AlarmFacade;
import com.htd.htdapmapi.alarm.request.AlarmInto;
import com.htd.htdapmapi.alarm.result.AlarmResult;
import com.htd.htdapmcommon.constants.ErrorCodeConstants;
import com.htd.htdapmservice.service.intf.OneAlertService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * 告警facade实现类
 *
 */
@Service(version = "1.0")
public class AlarmFacadeImpl implements AlarmFacade {

    private static final Logger LOGGER = LoggerFactory.getLogger(AlarmFacadeImpl.class.getName());

    @Autowired
    private OneAlertService oneAlertService;

    /**
     * 创建告警API
     */
    @Override
    public AlarmResult createAlarm(AlarmInto alarmInto) {
        LOGGER.info("调用创建告警接口入参{}", alarmInto);
        AlarmResult alarmResult = new AlarmResult();
        try {
            //参数校验
            if (null == alarmInto) {
                LOGGER.error("调用创建告警接口参数为空");
                alarmResult.setResponseCode(ErrorCodeConstants.NULL_VALUE_ERROR_CODE);
                alarmResult.setResponseMsg(ErrorCodeConstants.NULL_VALUE_ERROR_MSG);
                return alarmResult;
            }
            return oneAlertService.createAlarm(alarmInto);
        } catch (Exception e) {
            LOGGER.error("调用创建告警接口系统异常", e);
            alarmResult.setResponseCode(ErrorCodeConstants.SYSTEM_ERROR_CODE);
            alarmResult.setResponseMsg(ErrorCodeConstants.SYSTEM_ERROR_MSG);
            return alarmResult;
        }
    }
}
